import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
  uploads:'',
  location: {},
  address: "",
  food: {},
  goods:{},
  foods: {},
  goodmessage:{},
  tempAddress:null,
  id:'',
  username:''
}

const getters = {
  location: state => state.location,
  address: state => state.address,
  food: state => state.food,
  goods: state => state.goods,
  goodmessage: state => state.goodmessage,
  id: state => state.id,
  foods: state => state.foods,
  tempAddress: state => state.tempAddress,
  username:state=>state.username
}

const mutations = {
  setLocation(state, location) {
    if (location) {
      state.location = location;
    } else {
      location = null
    }
  },
  setAddress(state, address) {
    if (address) {
      state.address = address;
    } else {
      address = ""
    }
  },

  getfood(state,food){
state.food = food
  },
  saveFood(state, foods) {
    state.foods = foods;
  },
  getgoods(state,goods){
    state.goods = goods;
  },
getgoodmessage(state,goodmessage){
  state.goodmessage = goodmessage
},
setTempAddress(state,tempAddress){
  state.tempAddress = tempAddress;
},
getID(state,id){
  state.id = id
},
getUser(state,username){
state.username = username
}
}

const actions = {
  setLocation({commit}, location) {
    commit('setLocation',location)
  },
  setAddress({commit}, address) {
    commit('setAddress',address)
  },

  getfood({commit},food){
commit('getfood',food)
  },
  saveFood({
    commit
  }, foods) {
    commit('saveFood', foods);
  },
  getgoods({commit},goods){
    commit('getgoods',goods)
  },
  getgoodmessage({commit},goodmessage){
    commit('getgoodmessage',goodmessage)
  },
  setTempAddress({commit},tempAddress){
    commit('setTempAddress',tempAddress)
  },
  getID({commit},id){
    commit('getID',id)
  },
  getUser({commit},username){
    commit('getUser',username)
  }
}

export default new Vuex.Store({
  state,
  getters,
  mutations,
  actions
})